package com.javademo.algorithmstest;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Collections;

@Slf4j
public class AlgorithmsTest {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        ArrayList<Integer> list1 = new ArrayList<>();
        inputList(list);
        inputList1(list1);
        log.info("list: {}", list);
        log.info("list1: {}", list1);

        Collections.sort(list);
        log.info("list after sort: {}", list);

        log.info("所搜元素位置是1：{}", list.indexOf(6));
        log.info("所搜元素位置是2：{}", list.lastIndexOf(6));
        log.info("所搜元素位置是3：{}", Collections.binarySearch(list, 6));

        log.info("所搜元素存在次数: {}", Collections.frequency(list, 6));
        log.info("两个列表是否有公共元素：{}", !Collections.disjoint(list, list1));

        Collections.reverse(list);
        log.info("list after reverse: {}", list);

        Collections.shuffle(list);
        log.info("list after shuffle: {}", list);
    }

    private static void inputList(ArrayList<Integer> list){
        list.add(8);
        list.add(2);
        list.add(6);
        list.add(4);
        list.add(9);
        list.add(6);
    }

    private static void inputList1(ArrayList<Integer> list1){
        list1.add(7);
        list1.add(1);
        list1.add(5);
        list1.add(3);
        list1.add(8);
        list1.add(5);
    }
}
